package com.kgcx.coupon.controller;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.query.UserCouponQuery;
import com.kgcx.coupon.service.UserCouponService;
import com.kgcx.coupon.vo.coupon.UserCouponRespVO;
import com.kgcx.coupon.vo.coupon.UserCouponVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 何凯
 * @version 0.1
 * @description
 * @time 2017/12/27 16:07
 * @since 0.1
 */
@Api(description = "用户代金券管理", tags = "用户代金券管理接口")
@RestController
@RequestMapping("coupon/v1/userCoupon")
public class UserCouponController extends BaseController{
    @Autowired
    private UserCouponService userCouponService;
    /**
     * 主动发送历史查询
     * @param query
     * @return
     */
    @ApiOperation(value = "用户代金券查询", httpMethod = "POST", notes = "用户代金券查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping(value = "queryWithPage")
    public ReturnData<List<UserCouponVO>> queryWithPage(@RequestBody UserCouponQuery query){
        PageHelper.startPage(query.getPageNum(),query.getPageSize());
        List<UserCouponVO> list= userCouponService.selectUserCouponList(query);
        return new ReturnData<>(list);
    }
    @ApiOperation(value = "用户代金券明细查询", httpMethod = "GET", notes = "用户代金券明细查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "主键id", required = true, paramType = "query", dataType = "Integer", dataTypeClass = Integer.class)
    })
    @GetMapping("get")
    public ReturnData<UserCouponRespVO> getCouponInfo(@RequestParam Long kid) {
        UserCouponRespVO couponInfo = userCouponService.selectUserCouponById(kid);
        return new ReturnData<>(couponInfo);
    }
}
